import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.Date;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
public class ManagerTest {
    private Manager manager;
    private Movie testMovie;
    private Screening testScreening;
    @BeforeEach
    void setUp() {
        // 创建 Manager 对象
        manager = new Manager("manager001", "managerName", "managerPass", new Date(), "1234567890");
        // 创建测试电影
        testMovie = new Movie("movie001", "Test Movie", "Test Director","Test Actors" ,"Test Intro",100,7.5);
        // 创建测试放映场次
        testScreening = new Screening("screen001", testMovie,"1号厅",new Date(),50);
    }
    // 测试添加电影方法
    @Test
    void testAddMovie() {
        int beforeSize = manager.getMovies().size();
        manager.addMovie(testMovie);
        assertEquals(beforeSize + 1, manager.getMovies().size());
    }
    // 测试修改电影信息方法
    @Test
    void testModifyMovieInfo() {
        manager.addMovie(testMovie);
        Movie modifiedMovie = new Movie("movie001", "New Title", "New Director", "New Actors","New Intro",100,7.5);
        manager.modifyMovieInfo(modifiedMovie);
        Movie result = manager.findMovieById("movie001");
        assertEquals("Test Movie", result.getTitle());
    }
    // 测试删除电影方法
    @Test
    void testDeleteMovie() {
        manager.addMovie(testMovie);
        boolean result = manager.deleteMovie("movie001");
        assertTrue(result);
        Movie deletedMovie = manager.findMovieById("movie001");
        assertNull(deletedMovie);
    }
    // 测试添加放映场次方法
    @Test
    void testAddScreening() {
        int beforeSize = manager.getScreenings().size();
        manager.addScreening(testScreening);
        assertEquals(beforeSize + 2, manager.getScreenings().size());
    }
    // 测试修改放映场次方法
    @Test
    void testModifyScreening() {
        manager.addScreening(testScreening);
        testScreening.setTime(new Date());
        manager.modifyScreening(testScreening);
        Screening result = manager.findScreeningById("screen001");
        assertEquals(testScreening.getTime(), result.getTime());
    }
    // 测试根据范围列出放映场次方法（如今日、本周等 ）
    @Test
    void testListScreeningsByScope() {
        manager.addScreening(testScreening);
        List<Screening> screenings = manager.listScreeningsByScope("today");
        assertFalse(screenings.isEmpty());
    }
    // 测试查询销售数据方法
    @Test
    void testQuerySaleData() {
        manager.addScreening(testScreening);
        Ticket result = manager.querySaleData("scopeTest");
        assertNotNull(result);
    }
    // 测试查找电影方法
    @Test
    void testFindMovieById() {
        manager.addMovie(testMovie);
        Movie result = manager.findMovieById("movie001");
        assertEquals(testMovie, result);
    }
    // 测试查找放映场次方法
    @Test
    void testFindScreeningById() {
        manager.addScreening(testScreening);
        Screening result = manager.findScreeningById("screen001");
        assertEquals(testScreening, result);
    }
    // 测试登录、登出、密码管理方法
    @Test
    void testLoginLogoutManagePassword() {
        manager.login();
        manager.logout();
        manager.managePassword();
    }
    // 测试查看销售数据（日、周、月 ）方法
    @Test
    void testViewSales() {
        manager.viewDailySales();
        manager.viewWeeklySales();
        manager.viewMonthlySales();
    }
    // 测试更新电影方法
    @Test
    void testUpdateMovie() {
        manager.addMovie(testMovie);
        Movie newMovie = new Movie("movie001", "Updated Movie", "Updated Director", "Updated Actors","Updated Intro",100,7.5);
        assertTrue(manager.updateMovie("movie001", newMovie));
        Movie result = manager.findMovieById("movie001");
        assertEquals("Updated Movie", result.getTitle());
    }
}

